﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML.Graphics;
using System.Windows.Forms;
using SFML.Window;

namespace Strom.Client.Graphic
{
    public static class Functions
    {
        // Affichage d'un bout de tiles
        public static void DrawTiles(short mapNum, byte X, byte Y, byte Layer)
        {
            byte tX = 0;
            byte tY = 0;

            // Vérification de la couche
            switch (Layer)
            {
                case 0 :
                    Var.Tiles = new Sprite(GetTiles(Var.GameWorld.Maps[mapNum].Cells[X,Y].Sol.TilesNum));
                    tX = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sol.TilesX;
                    tY = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sol.TilesY;
                    break;
                case 1 :
                    Var.Tiles = new Sprite(GetTiles(Var.GameWorld.Maps[mapNum].Cells[X,Y].Inf[0].TilesNum));
                    tX = Var.GameWorld.Maps[mapNum].Cells[X, Y].Inf[0].TilesX;
                    tY = Var.GameWorld.Maps[mapNum].Cells[X, Y].Inf[0].TilesY;
                    break;
                case 2 :
                    Var.Tiles = new Sprite(GetTiles(Var.GameWorld.Maps[mapNum].Cells[X,Y].Inf[1].TilesNum));
                    tX = Var.GameWorld.Maps[mapNum].Cells[X, Y].Inf[1].TilesX;
                    tY = Var.GameWorld.Maps[mapNum].Cells[X, Y].Inf[1].TilesY;
                    break;
                case 3 :
                    Var.Tiles = new Sprite(GetTiles(Var.GameWorld.Maps[mapNum].Cells[X,Y].Inf[2].TilesNum));
                    tX = Var.GameWorld.Maps[mapNum].Cells[X, Y].Inf[2].TilesX;
                    tY = Var.GameWorld.Maps[mapNum].Cells[X, Y].Inf[2].TilesY;
                    break;
                case 4 :
                    Var.Tiles = new Sprite(GetTiles(Var.GameWorld.Maps[mapNum].Cells[X,Y].Sup[0].TilesNum));
                    tX = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sup[0].TilesX;
                    tY = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sup[0].TilesY;
                    break;
                case 5 :
                    Var.Tiles = new Sprite(GetTiles(Var.GameWorld.Maps[mapNum].Cells[X,Y].Sup[1].TilesNum));
                    tX = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sup[1].TilesX;
                    tY = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sup[1].TilesY;
                    break;
                case 6 :
                    Var.Tiles = new Sprite(GetTiles(Var.GameWorld.Maps[mapNum].Cells[X,Y].Sup[2].TilesNum));
                    tX = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sup[2].TilesX;
                    tY = Var.GameWorld.Maps[mapNum].Cells[X, Y].Sup[2].TilesY;
                    break;
                }

            // Affichage
            Var.Tiles.TextureRect = new IntRect(tX * 32,tY * 32,32,32);
            Var.Tiles.Position = new Vector2f(X*32,Y*32);
            if (Var.Tiles.Texture != null)
                Var.RenderWin.Draw(Var.Tiles);
            Var.Tiles.Dispose();
        }

        // Récupération du tiles à afficher
        public static Texture GetTiles(string tilesName)
        {
            for (byte i = 0; i < Var.TilesList.Length; i++)
            {
                if (tilesName == Var.TilesList[i])
                {
                    return Var.TexTiles[i];
                }
            }

            return new Texture(new Image(32,32,new Color(0,0,0,0)));
            /*
            MessageBox.Show("Tiles introuvable !", "Erreur",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            ClientManager.GUI.Game.Close();
            return null;*/
        }
    }
}
